package com.chenxin.quartz.task.mes;

import com.chenxin.common.utils.ConvertUtils;
import com.chenxin.interact.domain.UrlMap;
import com.chenxin.interact.domain.wmsToMes.WmsToMesOverdue;
import com.chenxin.interact.domain.mesNotice.OverdueNoticeDTO;
import com.chenxin.interact.handler.mesHandler.MesOverdueHandler;
import com.chenxin.interact.service.IUrlMapService;
import com.chenxin.interact.service.IWmsToMesOverdueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("overdueNoticeTask")
@Slf4j
public class OverdueNoticeTask {
    @Autowired
    private IUrlMapService urlMapService;
    @Autowired
    private MesOverdueHandler overdueHandler;
    @Autowired
    private IWmsToMesOverdueService overdueService;

    public void run(String method) {
        UrlMap urlMap = urlMapService.selectUrlMapByUrlNo("MES_POST_URL");
        if (urlMap == null) {
            log.error("接口【MES_POST_URL】未定义!");
            return;
        }
        // 获取待上报的出库检验信息
        List<WmsToMesOverdue> overdues = overdueService.selectWmsToMesOverdueList();
        if (overdues == null || overdues.size() == 0) {
            return;
        }
        // 数据转换
        List<OverdueNoticeDTO> overdueNotices = ConvertUtils.sourceToTarget(overdues, OverdueNoticeDTO.class);
        try {
            overdueHandler.notice(urlMap, overdueNotices, method);
        } catch (Exception e) {
            log.error("MES超期复检通知异常:{}", e);
        }
    }
}
